input 1: | input 2: |
---|---|
Rats | 12 |
|
|
try{}
and catch{}
Here is ONE form of the try
/catch
structure
(there are other forms soon to be discussed):
try { // statements, some of which might // throw an exception } catch ( SomeExceptionType ex ) { // statements to handle this // type of exception } .... // more catch blocks catch ( AnotherExceptionType ex ) { // statements to handle this // type of exception } // Statements following the structure
Here are a few syntax rules:
try{}
block can include:
catch{}
blocks following the try()
block.
catch{}
block.
This will be discussed in a few pages.catch{}
block describes the type of exception it handles.Is the following code fragment OK?
try { // various statements } catch (InputMismatchException ex ) { // various statements } catch (IOException ex ) { // various statements } System.out.println("Good-by" );